package router

import (
	"strconv"
	"tushare/common"
	"tushare/model"

	"github.com/gin-gonic/gin"
	"github.com/golang-module/carbon"
)

func (rt *Router) user() {
	userGroup := rt.R.Group("/user/")
	{
		userGroup.GET("collectCreate", func(c *gin.Context) {
			name := c.Query("name")
			url := c.Query("url")
			us := new(common.UserSession)
			userInfo := us.GetUserInfo(c)
			uc := model.UserCollect{}
			uc.Name = name
			uc.Url = url
			uc.UserId = userInfo.Id
			uc.CreateTime = carbon.Now().ToDateTimeString()
			model.UserCollectCreate(uc)
			c.JSON(200, gin.H{"code": 0, "message": "成功"})
		})

		userGroup.GET("collectList", func(c *gin.Context) {
			page, _ := strconv.ParseInt(c.Query("page"), 10, 64)
			pageSize, _ := strconv.ParseInt(c.Query("pageSize"), 10, 64)

			us := new(common.UserSession)
			userInfo := us.GetUserInfo(c)
			data := model.UserCollectList(page, pageSize, userInfo.Id)
			count := model.UserCollectCount(userInfo.Id)
			c.JSON(200, gin.H{"code": 0, "message": "成功", "data": data, "count": count})
		})
	}
}
